Method: Float#<=

Defined in:
numeric.c

#<=(other) ⇒ Boolean

Returns true if self is numerically less than or equal to other:

2.0 <= 3              # => true
2.0 <= 3.0            # => true
2.0 <= Rational(3, 1) # => true
2.0 <= 2.0            # => true
2.0 <= 1.0            # => false

Float::NAN <= Float::NAN returns an implementation-dependent value.

Returns:

  • (Boolean)


1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
# File 'numeric.c', line 1851

static VALUE
flo_le(VALUE x, VALUE y)
{
    double a, b;

    a = RFLOAT_VALUE(x);
    if (RB_INTEGER_TYPE_P(y)) {
        VALUE rel = rb_integer_float_cmp(y, x);
        if (FIXNUM_P(rel))
            return RBOOL(-FIX2LONG(rel) <= 0);
        return Qfalse;
    }
    else if (RB_FLOAT_TYPE_P(y)) {
        b = RFLOAT_VALUE(y);
#if MSC_VERSION_BEFORE(1300)
        if (isnan(b)) return Qfalse;
#endif
    }
    else {
        return rb_num_coerce_relop(x, y, idLE);
    }
#if MSC_VERSION_BEFORE(1300)
    if (isnan(a)) return Qfalse;
#endif
    return RBOOL(a <= b);
}